// pages/profile/index.js
import {getUserInfo} from '../../apis/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    myUserInfo: {},
    orderStatus: [
      {title:"全部订单", dataType:"all",icon: "orders-o"},
      {title:"待支付", dataType:"payment",icon: "pending-payment"},
      {title:"待发货", dataType:"delivery",icon: "logistics"},
      {title:"待收货", dataType:"received",icon: "sign"}
    ],
  },
  gotoLogin(){
    wx.navigateTo({
      url: "/pages/login/index",
    })
  },
  gotoMyOroder(ev){
    const datatype = ev.target.dataset.datatype
    wx.navigateTo({
      url: '/pages/myOrders/index?dataType='+datatype,
    })
    console.log('datatype===', datatype)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    const userInfo = wx.getStorageSync('userInfo')
    console.log("用户信息", userInfo)
    this.setData({
      userInfo: userInfo || {}
    })
    this.initData()
  },
  async initData(){
    const user = await getUserInfo()
    const uInfo = user.data.userInfo || {}
    this.setData({
      myUserInfo: uInfo
    })
  },
  gotoMyWallet(){
    const url = '/pages/profile/wallet/index?myUserInfo='+encodeURIComponent(JSON.stringify(this.data.myUserInfo))
    wx.navigateTo({
      url: url,
    })
  },
  gotoAddress(){
    wx.navigateTo({
      url: '/pages/profile/adress/index',
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})